package com.wj.tool.common.bean.restful;

import java.util.Arrays;

public class ResponseErrors {
    private static final int ERROR_SIZE = 255;
    private final ErrorNode[] errors = new ErrorNode[255];
    private int pointer = 0;

    public ResponseErrors() {
    }

    public final void addError(int code, String message) {
        if (this.pointer < 255) {
            this.errors[this.pointer++] = new ErrorNode(code, message);
        } else {
            throw new ArrayStoreException(" error size  over length, max length is :255");
        }
    }

    public final void addError(String message) {
        if (this.pointer < 255) {
            this.errors[this.pointer++] = new ErrorNode(message);
        } else {
            throw new ArrayStoreException(" error size  over length, max length is :255");
        }
    }

    public ErrorNode[] getErrors() {
        return (ErrorNode[]) Arrays.copyOf(this.errors, this.pointer);
    }

    public static class ErrorNode {
        private int code;
        private String details;

        public ErrorNode(String details) {
            this.details = details;
        }

        public ErrorNode(int code, String details) {
            this.code = code;
            this.details = details;
        }

        public int getCode() {
            return this.code;
        }

        public String getDetails() {
            return this.details;
        }
    }
}